<?php

namespace App\Http\Controllers;

use App\Http\Service\MsgService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\Http\Service\ViewcountService;
use Illuminate\Support\Facades\DB;

class MsgController extends BaseController
{
    private $getRules=[
            'type'=> 'required',
            //'city_code'=>'required',
        ];
    private  $getRulesMessage=[
            'type.required'=> 'type不能为空',
           // 'city_code.required'=> 'city_code不能为空',

        ];
    public $repository;
    public $historyservice;
    public function __construct(MsgService $repository,ViewcountService $historyservice)
    {
        parent::__construct();
        $this->repository = $repository;
        $this->historyservice = $historyservice;
    }

    /**
     *  互动消息 谁关注了我，谁评论了我，谁赞和收藏了我
     *  
     * @param Request $request
     * @return JsonResponse
     */
    public function getListall(Request $request)
    {
        $data=[
            'avatar'=>$request->json("avatar"),
            'article_url'=>$request->json("article_url"),
            'userId'=>$request->json("userId"),
            'userName'=>$request->json("userName"),
            'publicTime'=>$request->json("publicTime"),
            'title'=>$request->json("title"),
            'content'=>$request->json("content"),
            'replys'=>$request->json("replys"),
            'photos_url'=>$request->json("photos_url"),
            'unique_id'=>$request->json("unique_id"),
            'extractTime'=>$request->json("extractTime"),
            'push_task_id'=>$request->json("push_task_id"),
            'channel'=>'豆瓣',
            'group_name'=>$request->json("group_name"),

        ];
        $data['replys'] = json_encode($data['replys'], JSON_UNESCAPED_UNICODE);
        $data['content'] = json_encode($data['content'], JSON_UNESCAPED_UNICODE);
        $data['photos_url'] = json_encode($data['photos_url'], JSON_UNESCAPED_UNICODE);
        
        $this->success($this->repository->addData($request,$data));
    }

    #互相关注
    public function eachfocusList(Request $request)
    {
        
        $data=[
            'people_id'=>$request->json("people_id"),
            'keyword'=>$request->json("keyword"),

        ];
        $this->success($this->repository->eachfocusList($request,$data));
    }
   
    #用户关注其他用户信息
    public function userToOther(Request $request)
    {
         $data=[
            'people_id'=>$request->json("people_id"),
            'keyword'=>$request->json("keyword"),

        ];
        $this->success($this->repository->userToOther($request,$data));
    }

    #我的粉丝
    public function myFans(Request $request)
    {
        $data=[
            'people_id'=>$request->json("people_id"),
            'keyword'=>$request->json("keyword"),

        ];
        $this->success($this->repository->myFans($request,$data));
    }

    #互动消息
    public function allMsg(Request $request)
    {
        $data=[
            'people_id'=>$request->json("people_id"),
            'page'=>$request->json("page"),
            'limit'=>$request->json("limit"),
        ];
        $this->success($this->repository->allMsg($request,$data));
    }
    //个人中心展示：发布帖子数量，获得赞的数量，获得收藏的数量
    public function centerNum(Request $request)
    {
        $data=[
            'people_id'=>$request->json("people_id"),
        ];
        $this->success($this->repository->centerNum($request,$data));
    }
}
